// Package first
// @Author: zhangdi
// @File: first_permission_name
// @Version: 1.0.0
// @Date: 2023/11/28 17:41
package first

import (
	"server/application/db/system/columns"
	"server/application/db/system/dbdto"
	"server/application/db/system/dbsvc"
	"server/pkg/mylog"
	"server/pkg/where"
)

const perNameSyncOne = "sync_one"

// SetFirstPermissionData 设置默认的菜单数据
func SetFirstPermissionData() {
	menuList := formatListData()
	for _, menu := range menuList {
		//根据name来做唯一条件
		wheres := where.Format(where.Opt(columns.SysMenuName, "=", menu.Name))
		info, _ := dbsvc.SysMenuFindOne(wheres)
		if info != nil && info.ID > 0 { //已有数据则进行修改(只更改权限列表)
			//updateDto := new(dbdto.SysMenuUpdate)
			//utils.DtoToEntity(&menu, updateDto)
			//err := dbsvc.SysMenuUpdate(wheres, updateDto)
			err := dbsvc.SysMenuUpdate(wheres, &dbdto.SysMenuUpdate{Permissions: menu.Permissions})
			if err != nil {
				mylog.Error("SetFirstPermissionData()-update" + err.Error())
				continue
			}
		} else { //没有数据则进行插入
			_, err := dbsvc.SysMenuCreate(&menu)
			if err != nil {
				mylog.Error("SetFirstPermissionData()-create" + err.Error())
				continue
			}
		}
	}

}

func formatListData() []dbdto.SysMenuCreate {

	// SysMenuCreate slice
	// SysMenuCreate slice
	var menus = []dbdto.SysMenuCreate{
		{Name: "menu", Path: "/system/sysMenu", Component: "/system/sysMenu/index", Permissions: "create,update,delete,search,index", ParentId: 3, Sort: 900, Icon: "Menu", Title: "菜单管理", IsLink: "", IsHide: false, IsFull: true, IsAffix: true, IsKeepAlive: true},
		{
			Name:        "Home",
			Path:        "/home/index",
			Component:   "/home/index",
			Permissions: "index,sys_update", //sys_update是系统更新按钮，管理员才有的权限
			ParentId:    0,
			Sort:        10004,
			Icon:        "HomeFilled",
			Title:       "主页",
			IsLink:      "",
			IsHide:      true,
			IsFull:      true,
			IsAffix:     true,
			IsKeepAlive: true,
		},
		{Name: "Sys", Path: "sys", Component: "", Permissions: "index", ParentId: 0, Sort: 800, Icon: "Tickets", Title: "系统管理", IsLink: "", IsHide: false, IsFull: false, IsAffix: true, IsKeepAlive: true},
		{Name: "SysUser", Path: "/SysUser", Component: "/system/sysUser/index", Permissions: "create,update,delete,export,import,index,search", ParentId: 3, Sort: 300, Icon: "Menu", Title: "用户管理", IsLink: "", IsHide: false, IsFull: true, IsAffix: true, IsKeepAlive: true},
		{Name: "Dev", Path: "/", Component: "", Permissions: "index", ParentId: 0, Sort: 1, Icon: "Place", Title: "开发专用", IsLink: "", IsHide: false, IsFull: false, IsAffix: true, IsKeepAlive: true},
		{Name: "DyForm", Path: "/form/dynamicForm", Component: "/form/dynamicForm/index", Permissions: "create,update,delete,export,import,index", ParentId: 8, Sort: 1, Icon: "Cellphone", Title: "动态表单", IsLink: "", IsHide: false, IsFull: false, IsAffix: true, IsKeepAlive: true},
		{Name: "Generation", Path: "/generation/index", Component: "/generation/index", Permissions: "index,get_entity_names,get_entity_info,entity_save,gen_file", ParentId: 8, Sort: 1, Icon: "Coin", Title: "代码生成", IsLink: "", IsHide: false, IsFull: false, IsAffix: true, IsKeepAlive: true},
		{Name: "SysDictionary", Path: "/developer/dicManager", Component: "/developer/sysDictionary/index", Permissions: "create,update,delete,export,import,index,search", ParentId: 3, Sort: 1, Icon: "ChatDotRound", Title: "字典管理", IsLink: "", IsHide: false, IsFull: false, IsAffix: true, IsKeepAlive: true},
		{Name: "sysRole", Path: "/system/sysRole", Component: "/system/sysRole/index", Permissions: "create,update,delete,export,import,search,index", ParentId: 3, Sort: 1, Icon: "Orange", Title: "角色管理", IsLink: "", IsHide: false, IsFull: false, IsAffix: true, IsKeepAlive: true},
		{Name: "PubLot", Path: "/public/pubLot", Component: "/public/pubLot/index", Permissions: "index,create,update,delete,search", ParentId: 21, Sort: 1, Icon: "CollectionTag", Title: "批次列表", IsLink: "", IsHide: false, IsFull: false, IsAffix: false, IsKeepAlive: true},
		{Name: "PubGasStation", Path: "/public/pubGasStation", Component: "/public/pubGasStation/index", Permissions: "index,create,update,delete,search", ParentId: 21, Sort: 1, Icon: "Briefcase", Title: "气站管理", IsLink: "", IsHide: false, IsFull: false, IsAffix: false, IsKeepAlive: true},
		{Name: "PubDeliveryRecord", Path: "/public/pubDeliveryRecord", Component: "/public/pubDeliveryRecord/index", Permissions: "index,create,update,delete,search", ParentId: 21, Sort: 1, Icon: "ChatRound", Title: "交付说明", IsLink: "", IsHide: false, IsFull: false, IsAffix: false, IsKeepAlive: true},
		{Name: "sizhengUpload", Path: "/public/pubLot/components", Component: "/public/pubLot/components/create", Permissions: "index", ParentId: 21, Sort: 5, Icon: "Upload", Title: "四证上传", IsLink: "", IsHide: false, IsFull: false, IsAffix: false, IsKeepAlive: true},
		{Name: "dataCenter", Path: "/", Component: "", Permissions: "index,create,update,delete", ParentId: 0, Sort: 1, Icon: "DataLine", Title: "数据中心", IsLink: "", IsHide: false, IsFull: false, IsAffix: false, IsKeepAlive: true},
		{
			Name:      "PubQrLink",
			Path:      "/public/pubQrLink",
			Component: "/public/pubQrLink/index",
			//create_or_update：根据bq_url来判断新增或修改权限
			Permissions: "index,create,update,export,delete,search,sync_one,sync_batch,create_or_update",
			ParentId:    21,
			Sort:        1,
			Icon:        "Filter",
			Title:       "关联数据",
			IsLink:      "",
			IsHide:      false,
			IsFull:      false,
			IsAffix:     false,
			IsKeepAlive: true,
		},
		{Name: "sys_configs", Path: "/system/sysConfigs", Component: "/system/sysConfigs/setting", Permissions: "index,save", ParentId: 3, Sort: 1, Icon: "SetUp", Title: "系统配置", IsLink: "", IsHide: false, IsFull: false, IsAffix: false, IsKeepAlive: true},

		//定检信息
		{Name: "PubRecordCheck", Path: "/public/pubRecordCheck", Component: "/public/pubRecordCheck/index", Permissions: "index,create,update,delete,search", ParentId: 21, Sort: 1, Icon: "CircleCheck", Title: "定检数据", IsLink: "", IsHide: true, IsFull: false, IsAffix: false, IsKeepAlive: true},

		//充装信息
		{Name: "PubRecordFill", Path: "/public/pubRecordFill", Component: "/public/pubRecordFill/index", Permissions: "index,create,update,delete,search", ParentId: 21, Sort: 1, Icon: "CaretBottom", Title: "充装数据", IsLink: "", IsHide: true, IsFull: false, IsAffix: false, IsKeepAlive: true},
	}

	return menus
}
